﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using YAPL.Language.Compiler.CodeGen.ReflectionEmitGenerator.AstGen.Helpers;
using YAPL.Language.Core.Types;


namespace YAPL.Language.Compiler.CodeGen.ReflectionEmitGenerator.AstGen {
	public class ReInstanceVariableGenerator : ReExpressionGenerator {
		public ReInstanceVariableGenerator(ReCodeGenerator generator) : base(generator) {}
		public override void Generate(Ast.Expression expr) {
			var instanceVariableExpr = (Ast.InstanceVariableExpression)expr;
			var ilGen = Generator.Get<ILGenerator>(ReCodeGenerator.IL_GENERATOR_KEY);

			//get 'self' object on top of evaluation stack
			ilGen.EmitGetLocalVariableFromScope(YAPLFunction.SELF_PARAMETER);
			ilGen.EmitGetInstanceVariableFromObjectScope(instanceVariableExpr.Name);
		}
	}
}
